home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / Extras / bounce / BounceWindow.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.4 KB  |  143 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. //////////////////////////////////////////////////////////
  22. // BounceWindow.C
  23. //////////////////////////////////////////////////////////
  24. #include "Application.h"
  25. #include "BounceWindow.h"
  26. #include "Stage.h"
  27. #include "ControlPanel.h"
  28. #include "BounceClock.h"
  29. #include "QuitCmd.h"
  30. #include "UndoCmd.h"
  31. #include "CmdList.h"
  32. #include "AddBallCmd.h"
  33. #include "MenuBar.h"
  34. #include <Xm/Form.h>
  35. #include <Xm/Separator.h>
  36.  
  37. BounceWindow::BounceWindow ( char *name ) : MenuWindow ( name )
  38. {
  39.     _clock         = NULL;
  40.     _stage         = NULL;
  41.     _controlPanel  = NULL;
  42. }
  43. BounceWindow::~BounceWindow ()
  44. {
  45.     delete _clock;
  46.     delete _stage;
  47.     delete _controlPanel;
  48. }
  49. Widget BounceWindow::createWorkArea ( Widget parent )
  50. {
  51.     // The BounceWindow work area is implemented as a 
  52.     // form widget that contains the other components
  53.     // of the bounce interface
  54.     
  55.     Widget form =  XtCreateWidget ( "workArea", 
  56.                    xmFormWidgetClass,
  57.                    parent,
  58.                    NULL, 0 );
  59.     
  60.     // Create each major component of the bounce window
  61.     
  62.     _stage        = new Stage ( form, "stage" );
  63.     _clock        = new BounceClock ( form, "clock", _stage );
  64.     _controlPanel = new ControlPanel ( form, "control", _clock );
  65.     
  66.     // Set up the attachments to achieve the layout shown in Figure 12.1
  67.     
  68.     XtVaSetValues ( _controlPanel->baseWidget(),
  69.            XmNtopWidget,        _clock->baseWidget(),
  70.            XmNtopAttachment,    XmATTACH_OPPOSITE_WIDGET,
  71.            XmNleftAttachment,   XmATTACH_FORM,
  72.            XmNrightPosition,    50,
  73.            XmNrightAttachment,  XmATTACH_POSITION,
  74.            XmNbottomAttachment, XmATTACH_NONE,
  75.            NULL );
  76.     
  77.     XtVaSetValues ( _clock->baseWidget(), 
  78.            XmNtopAttachment,    XmATTACH_NONE,
  79.            XmNleftPosition,     50,
  80.            XmNleftAttachment,   XmATTACH_POSITION,
  81.            XmNrightAttachment,  XmATTACH_FORM,
  82.            XmNbottomAttachment, XmATTACH_FORM,
  83.            NULL );
  84.     
  85.     Widget sep =  
  86.     XtVaCreateManagedWidget ( "sep", 
  87.                  xmSeparatorWidgetClass,
  88.                  form,
  89.                  XmNleftAttachment,   XmATTACH_FORM,
  90.                  XmNrightAttachment,  XmATTACH_FORM,
  91.                  XmNtopAttachment,    XmATTACH_NONE,
  92.                  XmNbottomWidget,     _clock->baseWidget(),
  93.                  XmNbottomAttachment, XmATTACH_WIDGET,
  94.                  NULL );
  95.     
  96.     
  97.     XtVaSetValues ( _stage->baseWidget(),
  98.            XmNtopAttachment,    XmATTACH_FORM,
  99.            XmNleftAttachment,   XmATTACH_FORM,
  100.            XmNrightAttachment,  XmATTACH_FORM,
  101.            XmNbottomWidget,     sep,
  102.            XmNbottomAttachment, XmATTACH_WIDGET,
  103.            NULL );
  104.     
  105.     // Manage all the child widgets and return the form
  106.     
  107.     _controlPanel->manage();
  108.     _stage->manage();
  109.     _clock->manage();    
  110.     
  111.     return ( form );        
  112. }
  113. void BounceWindow::createMenuPanes ()
  114. {
  115.     // Create the main application menu, with just a quit and undo cmd
  116.     
  117.     CmdList *cmdList  = new CmdList();
  118.     Cmd     *quit     = new QuitCmd ( "Quit", TRUE );
  119.     cmdList->add ( theUndoCmd );        
  120.     cmdList->add ( quit );
  121.     _menuBar->addCommands ( cmdList, "Application" );
  122.     
  123.     // Create a menu for adding actors to the screen
  124.     
  125.     CmdList *actorList = new CmdList();
  126.     
  127.     Cmd *addRed   = new AddBallCmd ( "Add Red Ball",   TRUE, 
  128.                     _stage,  "Red"  );
  129.     Cmd *addGreen = new AddBallCmd ( "Add Green Ball", TRUE, 
  130.                     _stage, "Green" );
  131.     Cmd *addBlue  = new AddBallCmd ( "Add Blue Ball",  TRUE,
  132.                     _stage, "Blue"  ); 
  133.     Cmd *addAny   = new AddBallCmd ( "Add Ball...",    TRUE,
  134.                     _stage );    
  135.     
  136.     actorList->add ( addRed );
  137.     actorList->add ( addGreen );
  138.     actorList->add ( addBlue );
  139.     actorList->add ( addAny );
  140.     
  141.     _menuBar->addCommands ( actorList, "Actors" );
  142. }
  143.